package com.jade.explorer.ui.property;

import java.io.File;
import java.net.MalformedURLException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import com.jade.explorer.ui.SWTResourceManager;
import com.jade.explorer.views.JadeSharedImages;
import org.eclipse.swt.widgets.Label;

public class ImageProperty extends Dialog {
	
	private String _imgPath = null;
	private String _imgName = null;
	private String _ext = null;

	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public ImageProperty(Shell parentShell, String imgPath, String imgName, String extension) {
		super(parentShell);
		_imgPath = imgPath;
		_imgName = imgName;
		_ext = extension;
	}

	/**
	 * Create contents of the dialog.
	 * @param parent
	 */
	@SuppressWarnings("deprecation")
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		
		File f = new File(_imgPath);
		ImageDescriptor myImage;
		container.setLayout(null);
		
		
		Composite titleFrame = new Composite(container, SWT.NONE);
		titleFrame.setBounds(11, 13, 64, 64);
		titleFrame.setBounds(0, 0, 444, 44);
		titleFrame.setBackgroundImage(JadeSharedImages.getMenuTitleImg());
		
		titleFrame.setFont(SWTResourceManager.getFont("Rockwell", 14, SWT.BOLD));
		
		Label nameLabel = new Label(container, SWT.NONE);
		nameLabel.setBounds(10, 50, 424, 15);
		nameLabel.setText("Image Name : " + _imgName);
		
		Label pathLabel = new Label(container, SWT.NONE);
		pathLabel.setBounds(10, 71, 424, 15);
		pathLabel.setText("Image Path : " + _imgPath);
		
		try {
			myImage = ImageDescriptor.createFromURL(f.toURL());
			
			ImageData imgData = myImage.createImage().getImageData();
		
			Label bytesPerLineLabel = new Label(container, SWT.NONE);
			bytesPerLineLabel.setBounds(10, 113, 424, 15);
			bytesPerLineLabel.setText("Bytes per Line : " + imgData.bytesPerLine);
			
			Label heightLabel = new Label(container, SWT.NONE);
			heightLabel.setBounds(10, 134, 424, 15);
			heightLabel.setText("Image Height : " + imgData.height + " px");
			
			Label widthLabel = new Label(container, SWT.NONE);
			widthLabel.setBounds(10, 155, 424, 15);
			widthLabel.setText("Image Width : " + imgData.width + " px");
			
			Label depthLabel = new Label(container, SWT.NONE);
			depthLabel.setBounds(10, 176, 424, 15);
			depthLabel.setText("Image Depth : " + imgData.depth);
			
			Label usedSpaceLabel = new Label(container, SWT.NONE);
			usedSpaceLabel.setBounds(10, 197, 424, 15);
			usedSpaceLabel.setText("Usable Space : " + f.getUsableSpace() + " bytes");
			
			Label totalSpaceLabel = new Label(container, SWT.NONE);
			totalSpaceLabel.setBounds(10, 218, 424, 15);
			totalSpaceLabel.setText("Total Space : " + f.getTotalSpace() + " bytes");
			
			Label extensionLabel = new Label(container, SWT.NONE);
			extensionLabel.setBounds(10, 92, 424, 15);
			extensionLabel.setText("File Extension : " + _ext);
		
		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		}
		
		titleFrame.addPaintListener(new PaintListener() { 
			public void paintControl(PaintEvent e) { 
				e.gc.drawString("Image Property", 10, 10, true); 
				} 
		}); 
		
		return container;
	}

	/**
	 * Create contents of the button bar.
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(450, 318);
	}
}
